package com.example.loopyserver.controller;

import com.example.loopyserver.common.CommonController;
import com.example.loopyserver.dto.TaskDTO;
import com.example.loopyserver.dto.TaskResDTO;
import com.example.loopyserver.exception.CommonException;
import com.example.loopyserver.server.TaskService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Set;


@RestController
@CommonController
@RequiredArgsConstructor
@RequestMapping("/task")
public class TaskController {
    private final TaskService taskService;

    @GetMapping("")
    public TaskDTO pop(@RequestParam Set<String> accept) throws CommonException {
        return taskService.pop(accept);
    }

    @PostMapping("/{taskId}")
    public void submit(@PathVariable String taskId, @RequestBody @Valid TaskResDTO data) throws CommonException {
        taskService.submit(taskId, data.getRes());
    }
}
